# -*- coding:utf-8 -*-
import requests
import json

class RestApi():
    def __init__(self, api_url):
        self.url = "http://ip:port/" + api_url #这里自行更改为自己的服务ip和端口
        self.session = requests.session()
        self.header = {
            "Accept": "*/*",
            "Content-Type": "application/json",
            "Connection": "keep-alive",
            "Accept-Encoding": "gzip, deflate, br",
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
        }
        

    def get(self, **kwargs):
        return self.session.get(self.url, **kwargs)

    def post(self, data=None, **kwargs):
        return self.session.post(self.url, data=json.dumps(data), headers=self.header, **kwargs)

    def put(self, data=None, **kwargs):
        return self.session.put(self.url, data=json.dumps(data), headers=self.header, **kwargs)

    def delete(self, data=None, **kwargs):
        return self.session.delete(self.url, data=json.dumps(data), headers=self.header, **kwargs)


